<?php

namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class Favorite extends Model
{
	
    protected $table = 'favorite';
    public $timestamps = false;

    public function getFavorite($uid)
    {
       return self::query()->where('user_id',$uid)->with(['job'=>function($query){
           $query->select()->with(['company' => function ($query) {
               $query->select('id','companyname','thumb','companycate','province','city','area');
           }]);
       }])->get()->map(function ($value){
           return $value['job'];
       });
    }
    public function setFavorite($uid,$jobId){
        self::query()->insert([
           'user_id'=>$uid,
           'job_id'=>$jobId,
       ]);
    }

    public function getIdByJobId($uid,$jobId){
      return  self::where(['user_id'=>$uid,'job_id'=>$jobId])->first();
    }


    public function job(){
        return $this->hasMany('App\Models\Job','id','job_id');
    }
}
